package com.learning.security.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.learning.security.controller.vo.RightSaveReqVO;
import com.learning.security.dal.dataobject.AdminRightDO;
import com.learning.security.dal.mysql.AdminRightMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 权限表 服务实现类
 * </p>
 *
 * @author xxx
 * @since 2024-10-04
 */
@Service
public class AdminRightServiceImpl extends ServiceImpl<AdminRightMapper, AdminRightDO> implements AdminRightService {
    @Autowired
    private AdminRightMapper adminRightMapper;

    @Override
    public boolean createRight(RightSaveReqVO reqVO) {

        return Db.save(new AdminRightDO().setName(reqVO.getName())
                .setPermission(reqVO.getPermission())
                .setType(reqVO.getType())
                .setSort(reqVO.getSort())
                .setStatus(reqVO.getStatus()));
    }

    @Override
    public AdminRightDO getRightByPermission(String permission) {
        return adminRightMapper.getRightByPermission(permission);
    }
}
